@extends('layouts.default')

@section('title', '日志管理')

@push('scripts')
    <script>
        var totalNUm = 0;
        var table;
        var form;
        var laypage;
        var layer;
        var laydate;
        var filters = {};

        $(function(){
            layui.use(['table', 'form', 'element', 'laypage', 'laydate'], function() {
                table = layui.table;
                element = layui.element;
                form = layui.form;
                laypage = layui.laypage;
                laydate = layui.laydate;
                layer = layui.layer;
                var nowTime = new Date().valueOf();
                var max = null;
                getList(1);

                var start = laydate.render({
                    elem: '#startdate',
                    type: 'date',
                    max: nowTime,
                    btns: ['clear', 'confirm'],
                    done: function(value, date){
                        endMax = end.config.max;
                        end.config.min = date;
                        end.config.min.month = date.month -1;
                    },
                    trigger:'click'
                });
                var end = laydate.render({
                    elem: '#enddate',
                    type: 'date',
                    max: nowTime,
                    done: function(value, date){
                        if($.trim(value) == ''){
                            var curDate = new Date();
                            date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
                        }
                        start.config.max = date;
                        start.config.max.month = date.month -1;
                    },
                    trigger:'click'
                });
                // 搜索
                form.on('submit(search)', function(data) {
                    filters = Object.assign({}, data.field);
                    getList(1);
                    renderPageBar(1);
                    return false;
                });
                // 重置
                form.on('submit(reset)', function(data) {
                    $('#qryForm')[0].reset();
                    filters = {};
                    getList(1);
                    renderPageBar(1);
                    return false;
                });

            });
        });

        // 获取页面数据
        function getList(page) {
            showloading(true);
            var para = {
                "page": page,
                "filters": filters
            };
            getLogList(para, function(res){
                showloading(false);
                if(res.code == 1) {
                    if(totalNUm != res.total) {
                        totalNUm = res.total;
                        renderPageBar(page)
                    }
                    table.render({
                        data: res.data,
                        elem: '#tablelsit',
                        limit: 10,
                       // even:true,
                        cols: [
                            [{
                                field: 'id',
                                title: '序号',
                                templet: function (data) {
                                    var curPage = $("#pageBar .layui-laypage-skip .layui-input").val();
                                    return (curPage-1)*10 + data.LAY_INDEX;
                                },
                                width: '8%',
                            }, {
                                field: 'opusertitle',
                                title: '用户名',
                                width: '14%'
                            }, {
                                field: 'actionname',
                                title: '操作类型',
                                width: '15%'
                            }, {
                                field: 'logcontent',
                                title: '备注',
                                width: '30%',
                                templet: function(d){
                                    return d.eventtypename +''+ d.logcontent;
                                }
                            }, {
                                field: 'ip',
                                title: '用户IP',
                                width: '12%'
                            }, {
                                field: 'optime',
                                title: '操作时间'
                            }]
                        ],
                        done: function(res, curr, count) {
                            setBtnPermission();
                            tdTitle();
                        },
                        page: false,
                        loading: true
                    });
                } else {
                    layer.msg(res.msg, {
                        time: 2000,
                        icon: 5
                    });
                }
            });
        }

        // 渲染页面
        function renderPageBar(page) {
            laypage.render({
                elem: 'pageBar',
                count: totalNUm, //数据总数，从服务端得到
                curr: page,
                limit: 10,
                first: '第一页',
                last: '最后一页',
                layout: ['count', 'prev', 'page', 'next', 'skip'],
                jump: function(obj, first) {
                    //首次不执行
                    if(!first) {
                        layer.closeAll();
                        getList(obj.curr)
                    }
                }
            });
        }
        function resetInput() {
            $('input[name="keyword"]').val('');
        }
    </script>
@endpush

@section('content')
<div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-md12" >                            
                    <div class="layui-form-item">
                        <form class="layui-form" action="" btnPermission="" id="qryForm">
                            <div class="layui-input-inline" style="width: 220px;">
                                <input type="text" name="startdate" class="layui-input" id="startdate" placeholder="开始时间">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 220px;">
                                <input type="text" name="enddate" class="layui-input" id="enddate" placeholder="结束时间">
                            </div>
                            <div class="layui-input-inline">
                                <input  style="padding-right: 32px;" type="text" name="keyword" class="layui-input" placeholder="请输入关键字搜索">
                                <a href="javascript:void(0)" onclick="resetInput()"> <i style="font-size: 18px;position: absolute;top: 9px; right: 6px;cursor: pointer;" class="layui-icon layui-icon-close"></i></a>
                            </div>
                            <div class="layui-input-inline">
                                <button type="button" class="pear-btn pear-btn-primary" lay-submit="" lay-filter="search" btnPermission="">查询</button>
                                <button type="button" class="pear-btn " lay-submit="" lay-filter="reset" btnPermission="">重置</button>
                            </div>
                        </form>                  
					</div>            
                </div>             
            </div>
        </div>
    </div>
    <div class="layui-card">
        <!-- <div class="layui-card-header" style="font-weight: bold">
            <div style="width: 200px;float: left;" >日志列表</div>
        </div> -->
        <div class="layui-card-body">
            <table class="layui-hide" id="tablelsit" lay-filter="tablelsit" ></table>
            <div class="pagebarbox" style="text-align: end"><div id="pageBar" class="pagebar"></div></div>
        </div>
    </div>
   

@endsection
